<template>
  <div>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <div>
      <FormPanel ref="formPanel" columnsRef="lhmReportModalCustomerGrade" :list="formList" :cols="3" :labelWidth="150" :formType="type" :isSubmitBtn="false" @formChange="formChangeHandle" />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
      <AjaxButton v-if="type !== 'show'" :click="saveDialog" type="primary">{{ btnText }}</AjaxButton>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getCustomerGrade } from '@/api/customerRepair/customerInfo/customerGrade';
import moment from 'moment';
import { phone } from '@/utils/validate';
export default {
  name: 'lhmReportModalNameCustomerGrade',
  components: {},
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'edit'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.conf = { add: '保 存', edit: '保 存' };
    this.saveData = {};
    this.paramVal = {};
    this.helpData = null;
    return {
      visible: false,
      formList: this.createFormList(),
      vbilltype: '',
      pchId: null
    };
  },
  computed: {
    btnText() {
      return this.conf[this.type];
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      if (this.type === 'edit') {
        // 更新接口需要的记录 ID
        this.id = this.rowData.id;
        this.nbid = this.rowData.nbid;
        this.formList.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
          //  if(this.rowData.vfdno!=null){
          //    x.vbreakdown.disabled = false;
          //    x.vclmspa.disabled = false;
          //  }
        });
      }
      if (this.type === 'add') {
        // 更新接口需要的记录 ID
        this.formList.forEach(x => {});
      }
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '客户级别',
          fieldName: 'customeRgrade'
        },
        {
          type: 'INPUT',
          label: '客户级别名称',
          fieldName: 'customeName'
        },
        {
          type: 'INPUT_NUMBER',
          label: '工时优惠率',
          fieldName: 'hourPreferential',
          placeholder: '请输入...',
          initialValue: 0
        },
        {
          type: 'INPUT_NUMBER',
          label: '材料优惠率',
          fieldName: 'materialPreferential',
          placeholder: '请输入...',
          initialValue: 0
        },
        {
          type: 'CHECKBOX',
          label: '停用',
          fieldName: 'cushaltId',
          options: {
            trueValue: '1',
            falseValue: '0'
          }
        },
        {
          type: 'DATE',
          label: '停用日期',
          fieldName: 'haltAt',
          disabled: true, // 表单变灰
          placeholder: '选择日期'
        },
        {
          type: 'CHECKBOX',
          label: '预置数据',
          fieldName: 'presetData',
          options: {
            trueValue: '1',
            falseValue: '0'
          }
        }
      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },

    async getInfo(val) {
      let res = {};
      res = await getSelectOrderType({ qualityId: val });
      if (res.resultCode === 200) {
        this.helpData = res.data;
      }
    },
    async saveDialog() {
      let res = {};
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA(); // 获取from改变时整个表单的值
      console.log('data', data);
      if (err) return;
      if (this.type === 'add') {
        res = await addReport({ ...this.paramVal, ...data });
      }
      if (this.type === 'edit') {
        this.paramVal.id = this.rowData.id;
        res = await updateReort({ ...this.paramVal, ...data });
      }
      if (res.resultCode === 200) {
        this.closeDialog('refresh');
      }
    },

    closeDialog(param) {
      this.$emit('close', false, param);
    }
  }
};
</script>

<style lang="less" scoped></style>
